# Maintainer: Chirantan Ekbote <chirantan.ekbote@gmail.com>
# Contributor: Sébastien Luttringer <seblu@aur.archlinux.org>
# Contributor: Tsekhovoy Eugene aka Krash <8552246@gmail.com>

#get it ready for gdb debugging
DEBUG=0

pkgname=mc-git
pkgver=4.8.17.120.g0cc2292
pkgrel=1
pkgdesc='GNU Midnight Commander is an s-lang based file manager'
url='https://midnight-commander.org/'
arch=('i686' 'x86_64')
license=('GPL')
depends=('glib2' 'slang' 'perl')
makedepends=('git')
conflicts=('mc' 'mc-cvs' 'mc-fork-svn' 'mc-mp' 'mc-slavz' 'mc-suse')
provides=('mc')
changelog=CHANGELOG
fixflushpatch="fix_the_sometimes_truncated_shell_output_in_mc.patch"
cannotcreatepipestreams_patch='createstreams.patch'
#ncursespatch='108.patch'
source=('git+https://github.com/MidnightCommander/mc'
"$fixflushpatch"
"$cannotcreatepipestreams_patch"
#"$ncursespatch"
)
if [ -n "$DEBUG" ]; then
  options+=(!strip)
fi
sha512sums=('SKIP'
            '20a73a8809758bd6b084c44fe37ee0b68f3116aea9105e96bf005a24bf1a9c2128edf133367cdbd7f3b5eec67a5765082ea2a8471379bb57cdf048db6bd6b4a9'
            '627c80632cee4ac7ef2aca60e536c4c1e5dfde3cb983f3dcd2bf23466952ee021e1176f8d0bf10115d28732548ccca2ed269316bb236378102f40b2bf8dff7ca')

pkgver() {
    cd mc
    git describe | sed 's/-/./g'
}

prepare() { #this is temporarily here, but should be in build() because of the git updates and --incremental parameter to makepkg requiring this to be reexecuted just in case the code changes are in fact requiring rerun of autogen/configure
    cd mc
    # http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=dcui/mc&id=338da10abcd744ab75dfb184f8f81370727e5653
    sed -i 's/pkglibexec_SCRIPTS = $(SCRIPTS_OUT)/pkgdata_SCRIPTS = $(SCRIPTS_OUT)/g' contrib/Makefile.am
    patch -Np1 -i "../${fixflushpatch}"
    patch -Np1 -i "../${cannotcreatepipestreams_patch}"
    #patch -Np1 -i "../${ncursespatch}"


    #otherwise the mc -V is reported wrong! and differs from the pkg version
    #i put one more clean after autogen below
    make clean || true

    #debug mode for gdb, in case seg faults
    if [ -n "$DEBUG" ]; then
      export CFLAGS="$CFLAGS -O0 -fbuiltin -g"
      export CXXFLAGS="$CXXFLAGS -O0 -fbuiltin -g"
    fi


    ./autogen.sh
    export MCREVISION=$(git describe --tags)
    ./configure                     \
	--prefix=/usr               \
	--sysconfdir=/etc           \
	--libexecdir=/usr/lib       \
	--enable-background         \
	--enable-network            \
	--enable-netcode            \
	--enable-charset            \
	--enable-nls                \
	--with-vfs                  \
	--with-edit                 \
	--with-screen=slang         \
	--without-x                 \
	--without-samba             \
	--without-gpm-mouse         \
	--without-gnome             \
	--without-debug             \
	--without-included-gettext  \
	--disable-dependency-tracking



    make clean

}

build() {
    cd mc
    echo ${MAKEFLAGS}
    make ${MAKEFLAGS}
}

package() {
    cd mc
    make DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 ft=sh et:
